package com.xinmachong.jwt_demo.controller;

import com.xinmachong.jwt_demo.result.ApiResponse;
import com.xinmachong.jwt_demo.util.JWTUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author meyer@HongYe
 */
@RestController
@RequestMapping("/v1/user")
public class UserController {

    
    @PostMapping("/login")
    public ApiResponse login(@RequestParam("username") String username,
                             @RequestParam("password") String password){
        Map<String,String> payload = new HashMap<>();
        payload.put("username",username);
        payload.put("password",password);
        String token = JWTUtils.getToken(payload);
        return new ApiResponse(200,"success",token);
    }


    @GetMapping("/test4JwtFun")
    public ApiResponse test4JwtFun(){
        return new ApiResponse(200,"success",1);
    }
}
